package pers.cocoadel.springcloud.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import pers.cocoadel.springcloud.domain.Order;
import pers.cocoadel.springcloud.entities.CommonResult;
import pers.cocoadel.springcloud.service.impl.OrderService;

import java.math.BigDecimal;

@RestController
public class OrderController
{
    private final OrderService orderService;

    @Autowired
    public OrderController(OrderService orderService)
    {
        this.orderService = orderService;
    }

    @GetMapping("/order/create/{userId}")
    public CommonResult<Order> createOrder(@PathVariable("userId") Long userId)
    {
        Order order = orderService.createOrder(userId, BigDecimal.valueOf(100), 10);
        return new CommonResult<>(200, "下订单成功！", order);
    }
}
